{extend name="adminblue/base" /}
{block name="resources"/}
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span class="color-red">*</span>名称:</dt>
		<dd>
			<p><input id="ap_name" type="text" value="{$info['ap_name']}" class="input-common"></p>
			<p class="error">请输入广告位名称</p>
		</dd>
	</dl>
	<dl>
		<dt>简介:</dt>
		<dd>
			<p><textarea id="editor" class="input-common">{$info['ap_intro']}</textarea></p>
		</dd>
	</dl>
	<dl>
		<dt>类别:</dt>
		<dd>
			<p>
				<select id="ap_class" name="account" class="form-control m-b input-common">
					<option value="0" {if condition="$info['ap_class'] eq 0"}selected{/if}>图片</option>
				</select>
			</p>
		</dd>
	</dl>
	<dl>
		<dt>是否启用:</dt>
		<dd>
			<p>
				<input id="is_use" type="checkbox" class="checkbox" {if condition="$info['is_use'] eq 1"}checked{/if}>
			</p>
		</dd>
	</dl>
	<dl>
		<dt>所在位置类型:</dt>
		<dd>
			<p>
				<label style="display: inline-block;font-weight:normal;"><input type="radio" name="type" id="type1" value="1" {if condition="$info['type'] eq 1"} checked {/if}> PC端</label>
				<label style="display: inline-block;font-weight:normal;margin-left:70px;"><input type="radio" name="type" id="type2" value="2" {if condition="$info['type'] eq 2"} checked {/if}> 手机端</label>
			</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="color-red">*</span>展示方式:</dt>
		<dd>
			<p id="ap_display">
				<label style="font-weight:normal;"><input type="radio" name="ap_display" id="ap_display0" value="0"  {if condition="$info['ap_display'] eq 0"}checked{/if}> 可以发布多条并幻灯展示</label>
				<label style="font-weight:normal;"><input type="radio" name="ap_display" id="ap_display1" value="1"  {if condition="$info['ap_display'] eq 1"}checked{/if}>  可以发布多条广告并随机展示</label>
				<label style="font-weight:normal;"><input type="radio" name="ap_display" id="ap_display2" value="2" {if condition="$info['ap_display'] eq 2"}checked{/if}> 只允许发布并展示一条广告</label>
			</p>
			<p class="error">请选择展示方式</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="color-red">*</span>宽度:</dt>
		<dd>
			<p><input id="ap_width" type="number" value="{$info['ap_width']}" class="input-common"></p>
			<p class="error">请输入广告位宽度</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="color-red">*</span>高度:</dt>
		<dd>
			<p><input id="ap_height" type="number" value="{$info['ap_height']}" class="input-common"></p>
			<p class="error">请输入广告位高度</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="color-red">*</span>默认图片:</dt>
		<dd>
			<div class="class-logo"><p><img id="imgLogo" {if condition="$info['default_content'] !=''"} src="{:__IMG($info['default_content'])}" {/if} ></p></div>
			<div class="upload-btn">
				<span>
					<input class="input-file" name="file_upload" id="uploadImg" type="file" onchange="imgUpload(this);">
					<input type="hidden" id="Logo"/>
				</span>
				<p><i class="fa fa-cloud-upload"></i>上传图片</p>
			</div>
		</dd>
	</dl>
	<dl>
		<dt>默认背景色:</dt>
		<dd>
			<input id="ap_background_color" type="color" style="width:60px;height:25px;" value="{$info['ap_background_color']}" class="input-common" />
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd><button class="btn-common btn-big" onclick="updateShopAdvPositionAjax();">保存</button></dd>
	</dl>
</div>
<input type="hidden" id="ap_id" value="{$info['ap_id']}">
{/block}
{block name="script"}
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>
function imgUpload(event) {
	var fileid = $(event).attr("id");
	var data = { 'file_path' : UPLOADADV };
	uploadFile(fileid,data,function(res){
		if(res.code){
			$("#imgLogo").attr("src",__IMG(res.data));
			$("#Logo").val(res.data);
			showTip(res.message,"success");
		}else{
			showTip(res.message,"error");
		}
	});
}

function updateShopAdvPositionAjax() {
	var ap_id = $("#ap_id").val();
	var ap_name = $("#ap_name").val();
	var ap_intro = $("#editor").val();
	var ap_class = $("#ap_class").val();
	if($("#is_use").prop("checked")){
		var is_use = 1;
	}else{
		var is_use = 0;
	}
	var ap_display = $("input[type='radio'][name='ap_display']:checked").val();
	var ap_width = $("#ap_width").val();
	var ap_height = $("#ap_height").val();
	if($("#Logo").val().length > 0){
		var default_content = $("#Logo").val();
	}else{
		var default_content = "{$info['default_content']}"; 
	}
	var ap_background_color = $("#ap_background_color").val();
	var type = $("input[type='radio'][name='type']:checked").val();
	if(verify(ap_name,ap_display,ap_width,ap_height)){
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/system/updateshopadvposition')}",
			data : {
				'ap_name' : ap_name,
				'ap_id' : ap_id,
				'ap_intro' : ap_intro,
				'ap_class' : ap_class,
				'is_use' : is_use,
				'ap_display' : ap_display,
				'ap_width' : ap_width,
				'ap_height' : ap_height,
				'default_content' : default_content,
				'ap_background_color' : ap_background_color,
				'type' : type,
			},
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', "编辑成功","{:__URL('ADMIN_MAIN/system/shopadvpositionlist')}");
				}else{
					showMessage('error', "编辑失败");
				}
			}
		});
	}
	
}
function verify(ap_name,ap_display,ap_width,ap_height){
	if(ap_name.length == 0){
		$("#ap_name").parent().next(".error").show();
		$("#ap_name").focus();
		return false;
	}else{
		$(".error").hide();
	}
	if(ap_display == undefined){
		$("#ap_display").next(".error").show();
		return false;
	}else{
		$(".error").hide();
	}
	if(ap_width.length == 0){
		$("#ap_width").parent().next(".error").show();
		$("#ap_width").focus();
		return false;
	}else{
		$(".error").hide();
	}
	if(ap_height.length == 0){
		$("#ap_height").parent().next(".error").show();
		$("#ap_height").focus();
		return false;
	}else{
		$(".error").hide();
	}
	return true;;
}
</script>
{/block}